/*
 * Copyright (c) 2012 Universidad Antonio de Nebrija.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Apache License v2.0
 * which accompanies this distribution, and is available at
 * http://www.apache.org/licenses/LICENSE-2.0.html
 * 
 * Contributors:
 *    Universidad Antonio de Nebrija - initial API, implementation and documentation
 */
package com.nebrija.riif.cli;

import java.util.ArrayList;
import java.util.SortedMap;

/**
 * Command to print help for all the commands
 * @author asanchep
 *
 */
public class HelpCommand implements Command{
	
	SortedMap<String, Command> commands;

	public HelpCommand(SortedMap<String, Command> commands) {
		this.commands=commands;
	}

	@Override
	public String execute(ArrayList<String> params) throws CommandException {
		StringBuilder helpString = new StringBuilder("");
		if(commands!=null ){
			for(String k:commands.keySet()){
				helpString.append (k).append(commands.get(k).helpString()).append("\n");
			}
		}
		return helpString.toString();
	}

	@Override
	public String helpString() throws CommandException {
		return ": returns the list of commands";
	}

}
